#ifndef TAG_BUFFER_INCLUDE
#define TAG_BUFFER_INCLUDE
#include "buffer.h"
#include "data_define/Result.h"

class tTagBuffer : public tStreamBuffer
{
public:
	static const size_t		TAG_NAME_FIELD_SIZE			= 4;
	static const size_t		DATA_LENGTH_FIELD_SIZE		= 4;
	
	BYTE		GetTagByte(const char * Tag, eResult * Res);
	USHORT		GetTagShort(const char * Tag, eResult * Res);
	UINT		GetTagInt24(const char * Tag, eResult * Res);
	UINT		GetTagInt32(const char * Tag, eResult * Res);
	UINT64		GetTagInt64(const char * Tag, eResult * Res);
	tInt128		GetTagInt128(const char * Tag, eResult * Res);
	void		GetTagData(const char * Tag, PBYTE pData, unsigned int pData_size, eResult * Res);
	void		GetTagBuffer(const char * Tag, tBuffer * pBuf, eResult *Res);
	unsigned int	GetTagDataSize(const char * Tag, eResult *Res);

	void		WriteTagByte(const char * Tag, BYTE v);
	void		WriteTagShort(const char * Tag, USHORT v);
	void		WriteTagInt24(const char * Tag, UINT v);
	void		WriteTagInt32(const char * Tag, UINT v);
	void		WriteTagInt64(const char * Tag, UINT64 v);
	void		WriteTagInt128(const char * Tag, tInt128 v); 
	void		WriteTagData(const char * Tag, PBYTE ptr, unsigned int length);
	void		WriteEmptyTagData(const char * Tag, tBuffer * psb, unsigned int length);

	static size_t		ByteTagSize();
	static size_t		ShortTagSize();
	static size_t		Int24TagSize();
	static size_t		Int32TagSize();
	static size_t		Int64TagSize();
	static size_t		Int128TagSize();
	static size_t		DataTagSize(size_t DataSize);

	tTagBuffer();
private:
	void StartSearchTag();
	bool NextTag();
	bool SearchTag(const char * Tag, unsigned int &length);

	PBYTE m_pFirstTag;
	
};


class ifTagPresist
{
	virtual int Load(tTagBuffer & TagBuffer) = 0;
	virtual int Save(tTagBuffer & TagBuffer) = 0;
	virtual size_t GetSize() = 0;

};

#endif
